#include <iostream>


class Base
{
public:
    Base()
    {
        std::cout<<"父类构造"<<std::endl;
    }
    
    //将基类的析构函数声明为虚函数
    virtual ~Base()
    {
        std::cout<<"父类析构"<<std::endl;
    }
};

class Derived:public Base
{
public:
    Derived()
    {
        std::cout<<"子类构造"<<std::endl;
    }
    ~Derived()
    {
        delete a;
        std::cout<<"子类析构"<<std::endl;
    }
private:
    int *a;
};


int main()
{
    Base *d = new Derived;//用了向上转型 会导致子类不会调用析构函数 从而内存泄漏
    delete d;
    return 0;
}